package com.blockmeta.bbs.businesslibrary.base.fragment;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.LogUtils;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.interfaces.GetF10Bitmap;
import com.blockmeta.bbs.businesslibrary.interfaces.GetRecyclerView;
import com.blockmeta.bbs.businesslibrary.interfaces.TimeRefresh;
import com.trello.rxlifecycle2.components.support.RxFragment;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by author on 2017/12/26.
 */

public abstract class BaseFragment extends RxFragment implements GetRecyclerView, TimeRefresh, GetF10Bitmap {
    protected Unbinder mUnbinder;
    public Context mContext;

    @Override
    public void onAttach(Context context) {
        mContext = getActivity();
        super.onAttach(context);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        LogUtils.i("fragmentname" + this.getClass().getName());
        ARouter.getInstance().inject(this);
        View view = setContentView(inflater, container);
        mUnbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    public abstract View setContentView(LayoutInflater inflater, ViewGroup container);

    public abstract void initView();

    public void fragmentStartActivity( String path) {
        ARouter.getInstance().build(path)
                .navigation(mContext);
    }

    /**
     * 定向跳转搜索页面
     *
     * @param routerPath 路由地址
     * @param value 参数
     */
    public void fragmentStartActivity(String routerPath, String value) {
        ARouter.getInstance().build(routerPath)
                .withString(Constant.ZERO,value)
                .navigation();
    }

    /**
     * 跳转发布活动页面
     *
     * @param routerPath 路由地址
     * @param value1 参数1
     * @param value2 参数2
     */
    public void fragmentStartActivity(String routerPath, String value1, String value2) {
        ARouter.getInstance().build(routerPath)
                .withString(Constant.ZERO,value1)
                .withString(Constant.ONE,value2)
                .navigation(mContext);
    }

    /**
     * @param context
     * @param pair
     * @param exchange
     */
    public void startToDetailTicker(Context context, String pair, String exchange) {
        RouterHelper.startActivity(context, RouterPath.COINS_DETAIL_ACTIVITY,pair,exchange);
    }

    @Override
    public void onDestroyView() {
        mUnbinder.unbind();
        mUnbinder = null;
        super.onDestroyView();
    }

    /**
     * 在此处实现此接口并在需要使用处重载
     */
    @Override
    public RecyclerView getRecyclerView() {
        return null;
    }

    @Override
    public Bitmap getBitmap() {
        return null;
    }

    /**
     * 返回列表数据
     *
     * @return recycler数据
     */
    @Override
    public List getList() {
        return null;
    }

    @Override
    public void onTimeRefresh() {

    }
}
